package com.czl.elm.controller;


import com.czl.elm.domain.Users;
import com.czl.elm.service.IUsersService;
import com.czl.elm.util.ActionResult;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import javax.swing.*;
import java.util.Map;

import static java.awt.SystemColor.info;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zuoleiChen
 * @since 2021-05-15
 */
@RestController
@RequestMapping("/users")
@CrossOrigin
public class UsersController {

    @Autowired
    private IUsersService usersService;

    @ApiOperation(value="获取成员的所有信息")
    @ApiResponses({
            @ApiResponse(code = 200,message = "OK",response = Users.class),
    })

    @PostMapping("/getUsersProperty")
    public ActionResult getUsersProperty(){return usersService.getUsersProperty();}

    @ApiOperation(value="修改密码")
    @PostMapping("/setUsersPassword")
    public ActionResult setUsersPassword( String checkCode,String newpass){return usersService.setUsersPassword(checkCode,newpass);}

    @ApiOperation(value="修改昵称")
    @PostMapping("/setUsersUserName")
    public ActionResult setUsersUserName( String userName){return usersService.setUsersUserName(userName);}

    @ApiOperation(value="修改简介")
    @PostMapping("/setUsersInfo")
    public ActionResult setUsersInfo( String info){return usersService.setUsersInfo(info);}

    @ApiOperation(value="修改生日")
    @PostMapping("/setUsersBirthday")
    public ActionResult setUserBirthday( String birthday){return usersService.setUsersBirthday(birthday);}

    @ApiOperation(value="修改头像")
    @PostMapping("/setUsersProfile")
    public ActionResult setUserProfile(@RequestParam("file") MultipartFile file){return usersService.setUsersProfile(file);}

    @ApiOperation(value="添加地址")
    @PostMapping("/addUsersAddress")
    public ActionResult addUsersAddress(@RequestBody Map<String,Object> msg){ return usersService.addUsersAddress(msg);}

    @ApiOperation(value="显示地址")
    @PostMapping("/getUsersAddress")
    public ActionResult getUsersAddress(){return usersService.getUsersAddress();}

    @ApiOperation(value="删除地址")
    @PostMapping("/delUsersAddress")
    public ActionResult delUsersAddress(String addressId){return usersService.delUsersAddress(addressId);}

    @ApiOperation(value="修改默认地址")
    @PostMapping("/setDefaultUsersAddress")
    public ActionResult setDefaultUsersAddress(String addressId){return usersService.setDefaultUsersAddress(addressId);}

    @ApiOperation(value="修改地址")
    @PostMapping("/setUsersAddress")
    public ActionResult setUsersAddress( @RequestBody Map<String,Object> msg){
        String addressId=(String) msg.get("addressId");
        msg.remove("addressId");
        return usersService.setUsersAddress(addressId,msg);
    }

    @ApiOperation(value="设置商店购物车")
    @PostMapping("/setShopCart/{shopId}")
    public ActionResult setShopCart(@PathVariable  String shopId, @RequestBody Map<String,Object> msg){
        return usersService.setShopCart(shopId,msg);
    }

    @ApiOperation(value="获取商店购物车")
    @PostMapping("/getShopCart/{shopId}")
    public ActionResult getShopCart(@PathVariable  String shopId){

        return usersService.getShopCart(shopId);
    }


}
